const service = require("./smallChangeService.js");
/**
 * 零钱提现
 */
Page({

  /**
   * 页面的初始数据
   */
  data: {
    cashListData: "",
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onShow: function (options) {
    // 请求我的零钱信息列表
    this.requestCashListData()
  },

  requestCashListData: function () {
    let self = this
    service.getCashListData(
      function (data) {
        self.setData({
          cashListData: data
        })
      }
    )
  },
 
 /**
  * 兑换接口
  */
  requestObtainCash: function (code) {
    let self = this
    let params = {
      code: code
    }
    service.getCashObtaion(params,
      function (data) {
        wx.showToast({
          title: '兑换成功',
          icon: 'none'
        })
        // 刷新数据
        self.requestCashListData()
      }
    )
  },

  /**
   * 签到点击事件
   */
  itemObtainClick: function (event) {
    let item = event.currentTarget.dataset.itemdata
    if (item.num > 0) {
      this.requestObtainCash(item.code)
    } else {
      wx.navigateTo({
        url: '/redPacket/pages/signIn/signIn',
      })
    }
  },


  /**
   * 发布点击事件
   */
  itemReleaseClick: function (event) {
    let item = event.currentTarget.dataset.itemdata
    if (item.num > 0) {
      this.requestObtainCash(item.code)
    } else {
      wx.switchTab({
        url: '/pages/addProduct/shareproducts/shareProduct',
      })
    }
  },

  /**
   * 赠送点击事件
   */
  itemSendClick: function (event) {
    let item = event.currentTarget.dataset.itemdata
    if (item.num > 0) {
      this.requestObtainCash(item.code)
    } else {
      wx.switchTab({
        url: '/pages/addProduct/shareproducts/shareProduct'
      })
    }
  }
})